// packagePay/pages/place-file/place-file.js
import { placeFileList } from '../../api/pay.js'
import { placeFile} from '../../../api/app'
import user from '.../../../../../utils/user.js'
const app = getApp()
Page({
    data: {
        data: [],
        isAdmin: 0,
        searchText: '',
        pageNum: 0,
        hasNextPage: true,
        rangeArr:['全部','无打卡','需打卡'],
        jobType:''
    },
    onLoad(){
        this.setData({
            isAdmin: (!!user.isAdmin || !!user.isSuperAdmin)
        })
        this.init()
    },

    async onScreenCompany(event){
        console.log(event,'event')
        const { value } = event.detail
        this.setData({
            data:[],
            hasNextPage:true,
            pageNum:0,
            jobType:value==1?0:value==2?1:''
        })
        await this.init()
    },

    init(type=""){
        if(!this.data.hasNextPage){
            return
        }
        this.data.pageNum += 1
        placeFileList({
            pageNum: this.data.pageNum,
            pageSize: 20,
            searchText: this.data.searchText,
            type:this.data.jobType
        }).then(res=>{
            if(!res.hasNextPage){
                this.data.hasNextPage = false
            }
            this.data.data.push(...res.list)
            this.setData({
                data: this.data.data
            })
            console.log(this.data.data,'datadata')
        })
    },
    search(event){
        console.log(event)
        this.data.searchText = event.detail.value
        this.setData({
            searchText: event.detail.value,
            pageNum: 0,
            data: [],
            hasNextPage: true
        })
        this.init()
    },
    onCancelPlace(event){
        placeFile({
            id: event.currentTarget.dataset.id,
            isArchived: 0
        }).then(()=>{
            app.toast('取消归档成功','success')
            this.data.data.splice(event.currentTarget.dataset.index, 1)
            this.setData({
                data: this.data.data
            })
        })


    }
})